package com.kaifamiao.jdbc.data.dao;

import java.time.LocalDate;
import java.util.List;

public interface Dao<E,ID> {

    E find( ID id ) throws DaoException;

    List<E> findAll() throws DaoException;

    boolean save( E e ) throws DaoException;

    boolean update( E e ) throws DaoException;

    boolean delete( ID id ) throws DaoException;

    public default java.sql.Date toDate( LocalDate localDate ){
        if( localDate == null ) {
            return null;
        }
        return java.sql.Date.valueOf(localDate);
    }

    public default LocalDate toLocalDate( java.sql.Date date ){
        return date == null ? null : date.toLocalDate();
    }

}
